#!/bin/bash

# date_modified.sh - checks to see the most recent file modified in the
# TCDB directory, saving the date in a file

# Author: Dylan J. Sather
# Date created: 2009-06-15
# Last edited: 2009-06-15

# This script merits some explanation - we start by listing the files
# in the root web directory in chronological order, getting the top 3
# lines, and cutting out the first 2 lines with sed (the first line is 
# the set of headings; the next will be the date_modified file itself 
# if it was the last one modified; normally, if the files haven't been 
# edited in a while, this will be the case [since this script runs 
# everyday]. This script does its best to get this right enough...). 
# After that, we search for the date at which the file was modified
# and write that date to file.
# We enclose the entire set of commands with quotation marks and have
# bash execute AS A WHOLE. Otherwise, we won't have the requisite 
# priveleges to redirect output to a file and the script will fail

ROOT_DIR="/var/www/tcdb/html"

bash -c "ls -lt $ROOT_DIR | head -3 | sed 2,2d | grep -o '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}' > $ROOT_DIR/date_modified"

exit 0
